package com.jiangjiang.eshop.commodity.controller;

import com.jiangjiang.eshop.commodity.dto.GoodsDetailDTO;
import com.jiangjiang.eshop.commodity.service.GoodsDetailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName GoodsDetailController
 * @Description 商品详情管理
 * @Author jhw
 * @Date 2021/8/2 16:12
 * @Version 1.0
 **/
@Slf4j
@RestController
@RequestMapping("/commodity/goods/detail")
public class GoodsDetailController {
    @Autowired
    private GoodsDetailService goodsDetailService;


    /**
     * 根据商品id查询商品明细数据
     * @param goodsId 商品id
     * @return 商品详情页数据
     */
    @GetMapping("/queryByGoodsId")
    public GoodsDetailDTO queryByGoodsId(Long goodsId) {
        try {
            return goodsDetailService.queryByGoodsId(goodsId);
        } catch (Exception e) {
            log.warn("error",e);
        }
        return null;
    }

    /**
     * 保存商品详情也
     * @param detailDTO 商品详情页数据
     * @return 处理结果
     */
    @PostMapping("/saveGoodsDetail")
    public Boolean saveGoodsDetail(GoodsDetailDTO detailDTO) {
        try {
            return goodsDetailService.saveGoodsDetail(detailDTO);
        } catch (Exception e) {
            log.warn("error",e);
        }
        return false;
    }

    /**
     * 更新商品详情也数据
     * @param detailDTO 商品详情页数据
     * @return 处理结果
     */
    public Boolean updateGoodsDetail(GoodsDetailDTO detailDTO) {
        try {
            return goodsDetailService.updateGoodsDetail(detailDTO);
        } catch (Exception e) {
            log.warn("error",e);
        }
        return false;
    }

}
